<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" >
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">柜号:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createPlanNo" name="createPlanNo" placeholder="请输入柜号" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createSku" name="createSku" placeholder="请输入SKU" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">PO:</label>
                            <div class="col-sm-2">
                                <input type="text" id="erpProducePo" name="erpProducePo" placeholder="请输入PO" class="form-control">
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- START 右侧数据 -->

            <!-- START 操作按钮 -->
            <!-- END 操作按钮 -->
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">

                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 生成当前数据
                </button>
                <button  class="back-btn layui-btn  layui-btn-sm layui-btn-warm" style="margin-left: -2px">
                    <i class="fa fa-search" aria-hidden="true"></i>退回数据
                </button>
            </div>
            <!-- START 数据表格 -->
            <table id="planTable"
                   data-toolbar="#toolbar"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-url="/sea/physical/distribute/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer'}){}%>
<script>
    var $planTable = $('#planTable');
    $(function () {
        $('.back-btn').on('click',function () {
            layer.open({
                type: 2,
                scrollbar: false,
                area: ['800px','600px'],
                content: ['/sea/pdf/back.do', 'no']
            });
        });

        $('.export-btn').on('click',function () {
            var selDatas = $planTable.bootstrapTable('getSelections');
            console.log(selDatas);
            if( selDatas.length == 0 ){
                layer.msg('请选择要导出的',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
            }else{
                var ids = [],names = [];
                $.each(selDatas,function(i,d){
                    if(d.createPlanStatus !== 2)
                    {
                        layer.msg('无法导出未处理的记录!');
                        return false;
                    }
                    else
                    {
                        ids.push(d.createPlanNo);
                    }
                });
                ids = ids.join(',');
                layer.open({
                    title: false,
                    closeBtn: 0,
                    type: 2,
                    area: ['100%','100%'],
                    content: ['/sea/pdf/editPage.do?ids='+ids, 'yes']
                });
            }
        });

        // START 表格配置
        $planTable.bootstrapTable({
            pageSize:10,
            detailView: true,
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜型',
                    field: 'createPlanCabinetName',
                    align: 'center',
                    valign: 'middle'
                }, {
                    title: '运输',
                    field: 'createPlanTransport',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '国家',
                    field: 'createPlanCountry',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '装柜地点',
                    field: 'createPlanPlace',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '装柜时间',
                    field: 'createPlanPlaceDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总件数',
                    field: 'createPlanTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总箱数',
                    field: 'createPlanBox',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总体积',
                    field: 'createPlanVolume',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '小件数',
                    field: 'createPlanNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总毛重',
                    field: 'createWeightTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '总净重',
                    field: 'createKgTotal',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '状态',
                    field: 'createPlanStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 1:
                                result='未处理';
                                break;
                            case 2:
                                result='已分配';
                                break;
                            case 22:
                                result='待分配';
                                break;
                            case 3:
                                result='已发运';
                                break;
                            case 4:
                                result='已开船';
                                break;
                            case 5:
                                result='已清关';
                                break;
                            case 6:
                                result='已送货';
                                break;
                            case 7:
                                result='已入库';
                                break;
                            default:
                                result='';
                        }
                        return result;
                    }
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                $('.detail-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['700px','500px'],
                        content: ['/sea/pdf/record.do?createPlanNo='+id, 'yes']
                    });
                });

                $(".import-btn").on('click',function () {
                    var id = $(this).attr('data-val');
                    $("#id").val(id);
                    //修改
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        content: ['/sea/pdf/editPage.do?id='+id, 'yes']
                    });

                });
            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

        //初始化子表格(无线循环)
        function InitSubTable (index, row, $detail) {
            var parentId = row.id;
            var cur_table = $detail.html('<table id="disTable"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/physical/distribute/findByCreateId',
                method: 'get',
                clickToSelect: true,
                queryParams: { createId: parentId},
                ajaxOptions: { id: parentId },
                clickToSelect: true,
                //height: 500,
                detailView: false,//父子表
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'createShipmentId',
                        title: 'ShipmentId'
                    },
                    {
                        field: 'createSku',
                        title: 'SKU'
                    },{
                        field: 'createFnSku',
                        title: 'FNSKU'
                    },{
                        field: 'productName',
                        title: '产品名称'
                    },{
                        field: 'productColorName',
                        title: '颜色'
                    },{
                        field: 'productCm',
                        title: '尺码(CM)'
                    },{
                        field: 'productInch',
                        title: '尺码(INCH)'
                    },{
                        field: 'createNumber',
                        title: '数量'
                    },{
                        field: 'createPackage',
                        title: '装箱量'
                    },{
                        field: 'createBoxNumber',
                        title: '箱数'
                    },{
                        field: 'productContainCount',
                        title: '内含件数'
                    },{
                        field: 'createNumberTotal',
                        title: '总件数'
                    },{
                        field: 'createSupplierName',
                        title: '供应商'
                    },{
                        field: 'createWeightTotal',
                        title: '总毛重'
                    },{
                        field: 'createKgTotal',
                        title: '总净重'
                    },{
                        field: 'createVolumeTotal',
                        title: '总体积'
                    },{
                        field: 'erpProducePo',
                        title: 'PO号'
                    },{
                        field: 'erpProducePrice',
                        title: '采购单价'
                    },
                    {
                        title: '单位',
                        field: 'productUnit',
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        title: '报关名称',
                        field: 'productDeclarationName',
                        align: 'center',
                        valign: 'middle'
                    }],
                onLoadSuccess : function(){

                }
            });
        };
    });

    // 操作菜单
    var status;
    function optFormatter(value,row){
        var content = '';
        status=row.createPlanStatus;
        content += '&nbsp;<button class="detail-btn btn btn-xs btn-default" data-val="'+row.createPlanNo+'" title="下载附件"> 下载附件</button>';
        return content;
    }

    $('.search-btn').on('click',function(){
        $planTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/physical/distribute/findByCnd.do?'+$('#search-form').serialize() });
    });

</script>
</body>
</html>
